//
//  ComepareTableViewCell.m
//  TravelDiary
//
//  Created by lanou3g on 15/11/16.
//  Copyright © 2015年 YDB MAC. All rights reserved.
//

#import "ComepareTableViewCell.h"
#import <UIImageView+WebCache.h>
#import <AVOSCloud.h>
#import "ComepareCollectionViewCell.h"
#import "HomeModel.h"
@interface ComepareTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>


@property(nonatomic,strong)HomeModel * homeModel;


@end
@implementation ComepareTableViewCell

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1 ;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.UrlArray.count ;
}

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ComepareCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    [cell.ImaView sd_setImageWithURL:[NSURL  URLWithString:_UrlArray[indexPath.row]] placeholderImage:[UIImage imageNamed:@"cellbg"]];

       return cell ;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
    return CGSizeMake(40, 40);
}

#pragma NSDate 转Nsstring

- (NSString *)stringFromDate:(NSDate *)date{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    
    
    //zzz表示时区，zzz可以删除，这样返回的日期字符将不包含时区信息。
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz"];
    NSString *destDateString = [dateFormatter stringFromDate:date];
    return destDateString;
    
    
}
- (void)awakeFromNib {
   
    self.iconImageView.layer.masksToBounds = YES;
    self.iconImageView.layer.cornerRadius = self.iconImageView.frame.size.width/2;
    
    UICollectionViewFlowLayout * flowaLayout = [[UICollectionViewFlowLayout alloc] init];
    flowaLayout.itemSize = CGSizeMake(self.contentView.frame.size.width/5 ,120);
    
    
    self.collView =
    [[UICollectionView alloc] initWithFrame:
     CGRectMake(self.frame.origin.x+10,self.FBSJ.frame.origin.y+30 ,[UIScreen mainScreen].bounds.size.width-20,self.frame.size.height- 170)
                                       collectionViewLayout:flowaLayout];
    
    
    
    [_collView registerClass:[ComepareCollectionViewCell  class] forCellWithReuseIdentifier:@"cell"];
    
    
    [_collView registerNib:[UINib nibWithNibName:@"ComepareCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"cell"];
    
    self.collView.delegate =self ;
    
    self.collView.dataSource = self ;
    
    flowaLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal ;
    self.collView.backgroundColor =[UIColor clearColor];
    
    [self.contentView addSubview: self.collView];
    
    
    

    
        
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.collView.frame =   CGRectMake(self.frame.origin.x+10,self.FBSJ.frame.origin.y+30 ,[UIScreen mainScreen].bounds.size.width-20,120);
    [self.Context sizeToFit];
}


-(void)setMoeld:(HomeModel *)moeld
{
    if (_moeld != moeld) {
        
        self.UseName.text = moeld.useName ;
        
        self.Context.text =moeld.content ;
        self.UrlArray =(NSMutableArray*) moeld.urlArray;
        NSString *dateStr = [moeld.creatDate substringToIndex:20];
        self.FBSJ.text = [NSString stringWithFormat:@"发布时间:%@",dateStr];
  
    }
    
}
@end
